Print a complex number and its real and imaginary partsΒΆ
Print a complex number and its real and imaginary parts.
Expected Output:
Complex Number: (2+3j)
Complex Number - Real part: 2.0
Complex Number - Imaginary part: 3.0
#Initialize a complex number
cn = complex(2, 3)
print("Complex Number: ", cn)
print("Complex Number - Real part: ", cn.real)
print("Complex Number - Imaginary part: ", cn.imag)
Output:
Complex Number: (2+3j)
Complex Number - Real part: 2.0
Complex Number - Imaginary part: 3.0